/*
*
* @desc
* */
const {createUrlParams} =require( "../common/utils");

const {getUrlParams} = require("../common/utils");

const {ddl2json} = require("../common/ddl2json");

const {initEnv} = require("../common/parseEnv");
const {
    connect,
    add,
    update,
    getOne,
    getList,
    getCount,
} = require('../common/db.js')

const path = require('path')
initEnv(path.resolve(__dirname, '.env'))

var params = {
    host: process.env.host,
    user: process.env.user,
    password: process.env.password,
    database: process.env.database,
}
console.log("params", params)
connect(params)
const axios = require("axios")

function 获取ddl2json() {
    var a = ddl2json('CREATE TABLE `act_evt_log` (\n' +
        '  `LOG_NR_` bigint(20) NOT NULL AUTO_INCREMENT,\n' +
        '  `TYPE_` varchar(64) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `PROC_DEF_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `PROC_INST_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `EXECUTION_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `TASK_ID_` varchar(64) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `TIME_STAMP_` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),\n' +
        '  `USER_ID_` varchar(255) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `DATA_` longblob,\n' +
        '  `LOCK_OWNER_` varchar(255) COLLATE utf8_bin DEFAULT NULL,\n' +
        '  `LOCK_TIME_` timestamp(3) NULL DEFAULT NULL,\n' +
        '  `IS_PROCESSED_` tinyint(4) DEFAULT \'0\',\n' +
        '  PRIMARY KEY (`LOG_NR_`) USING BTREE\n' +
        ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;')
    /*  { LOG_NR_: '',
          TYPE_: '',
          PROC_DEF_ID_: '',
          PROC_INST_ID_: '',
          EXECUTION_ID_: '',
          TASK_ID_: '',
          TIME_STAMP_: '',
          USER_ID_: '',
          DATA_: '',
          LOCK_OWNER_: '',
          LOCK_TIME_: '',
          IS_PROCESSED_: '' }*/

    console.log(a)
}


// http://ems.coolgua.com/v2/approval/
// 651c6ddfc52b9fb86c4fa56641917ba6/
// 2f9a67ba850b4a3b86733d9397503a2b/
// 686f6c5911ca4757bdb0832b335f1f31/
// list?
// exhibitionId=686f6c5911ca4757bdb0832b335f1f31
// &formType=1+&action=
// &type=0&
// roleId=
// &dateDiff=&
// key=&pageSize=20&
// pageNo=1&ph=1
async function 查询审批列表() {
    /* 查询空 也就是 添加的时候有问题*/
    var result = await getList("ems_apply_data", {
        exhibition_id: '686f6c5911ca4757bdb0832b335f1f31',
        formType: '1+',
        action: '',
        type: '0',
        roleId: '',
        dateDiff: '',
        key: '',
        pageSize: '20',
        pageNo: '1',
        ph: '1'
    })
    console.log(result)
}

var a = getUrlParams('http://ems.coolgua.com/v2/approval/651c6ddfc52b9fb86c4fa56641917ba6/2f9a67ba850b4a3b86733d9397503a2b/686f6c5911ca4757bdb0832b335f1f31/list?exhibitionId=686f6c5911ca4757bdb0832b335f1f31&formType=1+&action=&type=0&roleId=&dateDiff=&key=&pageSize=20&pageNo=1&ph=1')
var b = getUrlParams('http://localhost:8020/merchant/686f6c5911ca4757bdb0832b335f1f31/register_info.htm?fp=null&exhibitorId=16c445ca1d774e93a37f3be140c07c30&mobile=18819448261&status=0&dataId=9ae73432508246899041581a4a9ba077')
console.log(a)


/*{ fp: 'null',
    exhibitorId: '16c445ca1d774e93a37f3be140c07c30',
    mobile: '18819448261',
    status: '0',
    dataId: '9ae73432508246899041581a4a9ba077' }*/

console.log(b)
// 获取ddl2json()
// 查询审批列表()
/*
*
* @desc
* 提交审批
* 添加task   -> @DoProcess 所有添加任务 com.coolgua.ems.common.aop.ProcessStartAop#createProcess
* */
async function 修改审核() {
    /*
    *
    * */
    var queryParams=  {
        "formId": "4e028dc2d2e74e25a24f8f7c39778546",
            "status": "0",
            "file": "",
            "mapVo['biz_license']": "94ac7baf477a4f9baa8729d32e4b6494",
            "mapVo['reg_num']": "91371312MA3TBB8422",
            "mapVo['type']": "有限责任公司(自然人投资或控股)",
            "mapVo['person']": "陈清洁",
            "mapVo['capital']": "叁佰万元整",
            "mapVo['period']": "2020年06月22日至长期",
            "mapVo['set_date']": "2020年06月22日",
            "mapVo['group_id']": "sy004",
            "mapVo['company_name']": "山东连晟劳保用品有限公司",
            "typeId": "4",
            "mapVo['industry_category']": "0_0_1591542428995_3_1591542445520",
            "mapVo['telephone']": "15964095350",
            "mapVo['address']": "山东省临沂市河东区九曲街道陈家庄村卫生室北500米路北",
            "mapVo['booth_type']": "特装",
            "mapVo['booth_num']": "1",
            "mapVo['contact']": "张连成",
            "mapVo['mobile']": "18819448261",
            "mapVo['email']": "",
            "mapVo['invoice_type']": "专用发票",
            "mapVo['tax_id']": "91371312MA3TBB8422",
            "mapVo['invoice_company']": "山东连晟劳保用品有限公司",
            "mapVo['register_address']": "山东省临沂市河东区九曲街道陈家庄村",
            "mapVo['register_phone']": "15964095350",
            "mapVo['register_bank']": "中国农业银行股份有限公司临沂九曲分理处",
            "mapVo['bank_account']": "15873301040008118",
            "mapVo['addressee']": "张连成",
            "mapVo['addressee_phone']": "1596409530",
            "mapVo['addressee_address']": "山东省临沂市相公街道曹家店村",
            "mapVo['sngY_']": "",
            "lang": "cn",
            "dataId": "e64e38fd74954efb8e67698d78d4ab1e"
    }
    var result = await axios.post(`http://localhost:8020/merchant/686f6c5911ca4757bdb0832b335f1f31/null/16c445ca1d774e93a37f3be140c07c30/registerFormPost.action?${createUrlParams(queryParams)}`, {

    }, {
        headers: {
            "x-process": true,
            "x-user-id": '1cca43d84b7d44988f39ff114d986b93',
            "x-obj-id": '16c445ca1d774e93a37f3be140c07c30',
            "x-form-type": 20,
            "x-type": 4,
            "x-exhibition-id": '686f6c5911ca4757bdb0832b335f1f31'
        },
    }).then(res => res.data)
    debugger
    console.log("result", result)
}

// 修改审核()

/*
* @desc
* 登录用户
* @model [userModel]
*@session session.cur_user
* @flow
BaseController.java setUserAuth
* */
async function 模拟登录() {
    var result = await axios.get(`http://localhost:8020?fp=651c6ddfc52b9fb86c4fa56641917ba6`, {}, {
        headers: {
            'Content-Type': 'text/html'
        }
    }).then(res => res.data)
    debugger
}

// 模拟登录()

/*
* @desc
* 其实查询selectAllTask task列表
* 1. exhibition_id 686f6c5911ca4757bdb0832b335f1f31
* getFormType
* */
async function 审批查询列表() {
    var result = await axios.get(`http://localhost:8020/v2/approval/651c6ddfc52b9fb86c4fa56641917ba6/2f9a67ba850b4a3b86733d9397503a2b/686f6c5911ca4757bdb0832b335f1f31/list.htm`)
    debugger
}

审批查询列表()